﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Data;
using DevExpress.Utils;
using DevExpress.XtraGrid.Views.Grid;
using QuanLyKho.QuanLyChung;

namespace QuanLyKho.Control
{
    public partial class Quanly_Danhsachlenh : UserControl
    {
        public Quanly_Danhsachlenh()
        {
            InitializeComponent();
            Loaddata();
            SetPropertiesGrid();
            SetPropertiesColumns();
        }

        public void Loaddata()
        {
            DataTable data = DataAll.SelectAll("PhongMau_SanPham", "*", "Where TrangThai !=" + Convert.ToInt32(TrangThai.PhongMau_TaoMoi));
            gridLenh.DataSource = data;
        }

        public void SetPropertiesGrid()
        {
            gvLenh.BestFitColumns();
            gvLenh.FocusRectStyle = DrawFocusRectStyle.RowFullFocus;
            //gvLenh.OptionsBehavior.Editable = false;
            //gvLenh.OptionsSelection.EnableAppearanceFocusedCell = true;
            gvLenh.OptionsSelection.MultiSelect = true;
            gvLenh.OptionsView.ShowGroupPanel = false;
            //gvNhapKho.OptionsView.ColumnAutoWidth = false;
            gvLenh.OptionsView.ShowFooter = true;
            gvLenh.OptionsFind.AlwaysVisible = true;
            gvLenh.Columns["ID"].Visible = false;
        }

        public void SetPropertiesColumns()
        {        
            gcMaSanPham.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
            gcNgayLapLenh.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
            gcNguoiLapLenh.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
            gcSoLuong.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
            gcNgayGcNhanHang.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
            gcNgayGcTraHang.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
            gcNgayGuiLenh.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
            gcNgaySuaLenh.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
            gcTrangThai.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
            gcNgayChungTu.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
            gcNgayHoachToan.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
            gcSoChungTu.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
            gcGhiChu.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;


            //gcS.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Center;
            //gcM.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Center;
            //gcL.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Center;
            //gcXL.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Center;
            //gcTongCan.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Center;
            //gcDMTT.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Center;
            //gcSLCan.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Center;


        }

        private void gvLenh_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
        {
            if (e.Column.FieldName == "TrangThai")
            {
                e.DisplayText = Common.HienThiTrangThai(Convert.ToInt32(e.Value));
            }
        }

        private void gvLenh_DoubleClick(object sender, EventArgs e)
        {
            if (gvLenh.FocusedRowHandle >= 0)
            {
                HanhTrinh_Popup.SoChungTu = gvLenh.Columns["SoChungTu"].View.GetRowCellDisplayText(gvLenh.FocusedRowHandle, "SoChungTu");
                var lss = new HanhTrinh_Popup();
                lss.ShowDialog();
                Loaddata();
                HanhTrinh_Popup.SoChungTu = string.Empty;
            }    
        }
    }
}
